package com.zx.mes.senior.proxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import org.junit.Test;

/**
 * cglib 动态代理
 * @author huayunlong
 * @date 2018-7-30
 */
public class CglibProxyTest {


    @Test
    public void test(){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(PersonCglib.class);
        enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
///            System.out.println("obj:"+obj);
            System.out.println("method:"+method);
            System.out.println("proxy:"+proxy);
            return proxy.invokeSuper(obj,args);
        });

        PersonCglib o =(PersonCglib) enhancer.create();
        o.say("李四");

    }

    @Test
    public void test2(){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(PersonCglib.class);
        enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> proxy.invokeSuper(obj,args));

        PersonCglib o =(PersonCglib) enhancer.create();
        o.say("李四");
    }
}
